/*
 * Ext JS Library 2.2.1
 * Copyright(c) 2006-2009, Ext JS, LLC.
 * licensing@extjs.com
 * 
 * http://extjs.com/license
 */


Ext.onReady(function(){

    Ext.QuickTips.init();
    
     dsUsuarios = new Ext.data.Store({
        reader: new Ext.data.ArrayReader({}, [
               {name: 'idUsuario'},
               {name: 'idTipoUsuario'},
               {name: 'idDepartamento'},
               {name: 'login'},
               {name: 'password'},
               {name: 'sessionusr'},
               {name: 'nombres'},
               {name: 'apellidoPaterno'},
               {name: 'apellidoMaterno'},
               {name: 'nombreCompleto'},
               {name: 'rfc'},
               {name: 'email'},
               {name: 'giro'}
          ])
    });
  //  dsUsuarios.loadData(arrayData);

        var colModel = new Ext.grid.ColumnModel([
        {id:'idUsuario',header: "id", width: 60, sortable: true, dataIndex: 'idUsuario'},
        {header: "Login", width: 90, sortable: true, dataIndex: 'login'},
        {header: "Nombre", width: 200, sortable: true, dataIndex: 'nombreCompleto'},
        {header: "Email", width: 125, sortable: true,  dataIndex: 'email'},
        {header: "RFC", width: 85, sortable: true,  dataIndex: 'rfc'},
        {header: "Giro", width: 125, sortable: true,  dataIndex: 'giro'}
        
    ]);
    
  

    	var gpSolicitudes = new Ext.grid.GridPanel({
			id:'gpSolicitudes',
			title: 'Lista de Solicitudes',
			store: dsUsuarios,	
			width: 700,
			height:250,
			clicksToEdit:1,
			cm:colModel,
			frame:false,
			border: true,
			selModel: new Ext.grid.RowSelectionModel({singleSelect:true})

		});

    
    
    
    var msg = function(title, msg){
        Ext.Msg.show({
            title: title, 
            msg: msg,
            minWidth: 200,
            modal: true,
            icon: Ext.Msg.INFO,
            buttons: Ext.Msg.OK
        });
    };
    
  
    
    var fp = new Ext.FormPanel({
        renderTo: 'fi-form',
        fileUpload: true,
        width: 600,
        frame: true,
        title: 'Cargar un archivo de solicitudes',
        autoHeight: true,
        bodyStyle: 'padding: 10px 10px 0 10px;',
        labelWidth: 50,
        defaults: {
            anchor: '95%',
            allowBlank: false,
            msgTarget: 'side'
        },
        items: [{
            xtype: 'fileuploadfield',
            id: 'form-file',
            emptyText: 'Selecciona un archivo',
            fieldLabel: 'Archivo',
            name: 'photo-path',
            buttonCfg: {
                text: '',
                 iconCls : 'save'
            }
        },gpSolicitudes],
       // },gpSolicitudes],
        buttons: [{
            text: 'Guardar',
            handler: function(){
                if(fp.getForm().isValid()){
	                fp.getForm().submit({
	                    url: 'UploadArchivoServlet',
	                    waitMsg: 'Cargando Archivo...',
	                    success: function(fp, o){
	                        msg('Success', 'Processed file "'+o.result.file+'" on the server');
	                    }
	                });
                }
            }
        },{
            text: 'Reset',
            handler: function(){
                fp.getForm().reset();
            }
        }]
    });
    
    /*
        var fsf = new Ext.Panel({
        	renderTo: 'gridForm',
        	//collapsible: false,
        	defaults: {bodyStyle : 'padding:0px 0px 0;', border : false},
     		items: [{ //
				layout: 'table',
				//colspan:5,
				boder:false,
			   	defaults : {bodyStyle : 'padding:0px 0px 0;', border : false},
		    	layoutConfig: {columns: 1},
		    	items:[]
			}]
		});
		*/
		//fsf.render(document.body);
    
});